package es.udc.pfc.davidparedes.model.universemanager;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import es.udc.pfc.davidparedes.model.store.Store;
import es.udc.pfc.davidparedes.model.universe.Universe;
import es.udc.pfc.davidparedes.model.userprofile.UserProfile;

@Entity
@DiscriminatorValue("Manager")
public class UniverseManager extends UserProfile {

	private Calendar contractTermination;
	private Universe universe;
	
	public UniverseManager() {
	}
	
	public UniverseManager(String loginName, String encryptedPassword,
			String firstName, String lastName, String email, String nif,
			Store store, Calendar contractTermination) {
		super(loginName, encryptedPassword, firstName, lastName, email, nif, store);
		this.contractTermination = contractTermination;
	}

	@Column(name = "deletionDate")
	@Temporal(TemporalType.TIMESTAMP)
	public Calendar getContractTermination() {
		return contractTermination;
	}
	
	public void setContractTermination(Calendar contractTermination) {
		this.contractTermination = contractTermination;
	}
	
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="universe")
	public Universe getUniverse() {
		return universe;
	}
	
	public void setUniverse(Universe universe) {
		this.universe = universe;
	}
	
	@Override
	public String toString() {
		String s = super.getFirstName() + " " + super.getLastName();
		if (universe != null) {
			s += " (" + universe.getName() + ")";
		}
		return s;
	}
}
